package com.xquant.marketdata.marketdata.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.xquant.common.core.constant.Constants;
import com.xquant.common.core.constant.SecurityConstants;
import com.xquant.common.core.domain.R;
import com.xquant.marketdata.marketdata.domain.TfndDTO;
import com.xquant.marketdata.marketdata.domain.TfndDividendDTO;
import com.xquant.marketdata.marketdata.domain.TfndPriceDTO;
import com.xquant.marketdata.utils.CommResponse;
import com.xquant.system.api.RemoteUserService;
import com.xquant.system.api.SysConfigService;
import com.xquant.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.xquant.common.log.annotation.Log;
import com.xquant.common.log.enums.BusinessType;
import com.xquant.marketdata.marketdata.service.ITfndService;
import com.xquant.common.core.web.controller.BaseController;
import com.xquant.common.security.utils.ExcelUtil;
import com.xquant.common.core.web.page.TableDataInfo;

/**
 * 基金Controller newCloud
 *
 * @author zipeng.li
 * @date 2022-03-07
 */
@RestController
@RequestMapping("/tfndCtroller")
public class TfndController extends BaseController {
  @Autowired private ITfndService tfndService;



  /** 查询基金列表 */
  @RequestMapping("/queryFundInfoByPage.action")
  public TableDataInfo list(@RequestParam Map<String, Object> param ) {
    List<TfndDTO> list = tfndService.selectTfndList(param);
    for (TfndDTO tfndDTO : list) {
      tfndDTO.setInstrument(tfndDTO.getiCode()+ " " +tfndDTO.getaType()+" " +tfndDTO.getmType());
    }
    return getDataTable(list);
  }

  /** 查询基金分红列表 */
  @PreAuthorize("@ss.hasPermi('marketdata:equity:fund:fundBonus:list')")
  @RequestMapping("/queryFundDividendInfoByPage.action")
  public TableDataInfo queryFundDividendInfoByPage(@RequestParam Map<String, Object> param) {
    startPage();
     List<TfndDividendDTO> list = tfndService.selectTfndDividendList(param);
    return getDataTable(list);
  }

  /** 查询基金行情列表 */
  @PreAuthorize("@ss.hasPermi('marketdata:equity:fund:fundQuota:list')")
  @RequestMapping("/queryFundPriceInfoByPage.action")
  public TableDataInfo queryFundPriceInfoByPage(@RequestParam Map<String, Object> param) {
    startPage();
    List<TfndPriceDTO> list = tfndService.selectTfndPriceList(param);
    return getDataTable(list);
  }

  /** 修改基金行情列表 */
  @PreAuthorize("@ss.hasPermi('marketdata:equity:fund:fundQuota:price')")
  @RequestMapping("/updateFundPrice.action")
  public CommResponse updateFundPrice(@RequestBody TfndPriceDTO fundForm) {
    startPage();
    tfndService.updateFundPrice(fundForm);
    return CommResponse.success("修改成功");
  }
  /** 导出基金列表 */
  @PreAuthorize("@ss.hasPermi('marketdata:equity:fund:fundInfo:export')")
  @Log(title = "基金", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, @RequestParam Map<String, Object> param) {
    startPage();
    List<TfndDTO> list = tfndService.selectTfndList(param);
    ExcelUtil<TfndDTO> util = new ExcelUtil<TfndDTO>(TfndDTO.class);
    util.exportExcel(response, list, "基金信息");
  }

  /** 导出基金分红列表 */
  @PreAuthorize("@ss.hasPermi('marketdata:equity:fund:fundDividend:export')")
  @Log(title = "基金", businessType = BusinessType.EXPORT)
  @PostMapping("/exportfundDividend")
  public void exportfundDividend(
      HttpServletResponse response, @RequestParam Map<String, Object> param) {
    startPage();
    List<TfndDividendDTO> list = tfndService.selectTfndDividendList(param);
    ExcelUtil<TfndDividendDTO> util = new ExcelUtil<TfndDividendDTO>(TfndDividendDTO.class);
    util.exportExcel(response, list, "基金分红信息");
  }

  /** 导出基金行情列表 */
  @PreAuthorize("@ss.hasPermi('marketdata:equity:fund:fundQuota:export')")
  @Log(title = "基金", businessType = BusinessType.EXPORT)
  @PostMapping("/exportfundPrice")
  public void exportfundPrice(
      HttpServletResponse response, @RequestParam Map<String, Object> param) {
    startPage();
    List<TfndPriceDTO> list = tfndService.selectTfndPriceList(param);
    ExcelUtil<TfndPriceDTO> util = new ExcelUtil<TfndPriceDTO>(TfndPriceDTO.class);
    util.exportExcel(response, list, "基金行情信息");
  }

  @RequestMapping("/getLastWorkday.action")
  public CommResponse getLastWorkday() {
    String lastWorkday = tfndService.getLastWorkday();
    CommResponse commResponse = new CommResponse(true);
    commResponse.setMsg(lastWorkday);
    return commResponse;
  }
}
